<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<link href="css/header.css" rel="stylesheet" />
	</head>

	<body>
		
		<!-- 标题栏 -->
		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<!-- 制作搜索按键 -->
			<a id="submit_searchFriends" class="mui-icon mui-icon-right-nav mui-pull-right" style="color: white;font-size: 14px;line-height: 26px;">搜索</a>
			<h1 class="mui-title title-color">搜索用户</h1>
		</header>
		
		<div class="mui-content">
			<div class="mui-input-row">
				<input id="search_username" type="text" class="mui-input-speech mui-input-clear" placeholder="请输入查找的用户名">
			</div>
			
		</div>
				
		<script src="js/mui.js"></script>
		<script src="js/app.js" ></script>
		<script type="text/javascript">
			mui.init();
			
			mui.plusReady(function () {
			    
				//获取当前用户信息
				var user =  app.getUserGlobalInfo();
				var myUserId = user.id;
				
				//点击时事件
				var submit_searchFriends = document.getElementById("submit_searchFriends");
				submit_searchFriends.addEventListener("tap",function(){
					//请稍候
					plus.nativeUI.showWaiting("请稍后...");
					//获取搜索的用户名
					var search_username = document.getElementById("search_username");
					
					var friend_username = search_username.value;
					//发送ajax请求,查询该用户
					mui.ajax(app.serverUrl + '/user/searchFriends?myUserId='+myUserId+'&username='+friend_username,{
						data:{},
						dataType:'json',//服务器返回json格式数据
						type:'post',//HTTP请求类型
						timeout:10000,//超时时间设置为10秒；
						success:function(data){
							//服务器返回响应,ResponseResult类型
							plus.nativeUI.closeWaiting();
							if(data.status == 200){
								//可以添加好友,跳转到详情页
								mui.openWindow({
									url: "searchFriendsResult.html",
									id: "searchFriendsResult.html",
									style: {},
									//传递添加的好友的信息
									extras: {
										add_friend : data.data
									}
								});
							}else{
								app.showToast(data.msg,"error");
							}
							
						},						
						
					});					
				})
			});
			
		</script>
	</body>

</html>
